home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #14
/
Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO
/
lan
/
printqv1.zip
/
PRINTQ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-03
|
11KB
|
315 lines
#include "printq.h"
int maincounter=0, wnum=0, twoormore=NO, SHOWONLY=NO;
Winrec buffer[MAXWINDOW];
void main(int argc, char *argv[])
{ int servercount, serversattached, loop;
// unsigned x=1,y=1;
char *achar, *achar2;
_setcursortype(_NOCURSOR);
clrscr();
if (argc = 2)
{ if (strcmp(strupr(argv[1]),"/?") == 0)
{ displayhelp();
_setcursortype(_NORMALCURSOR);
exit(1);
}
if (strcmp(strupr(argv[1]),"/Q") == 0)
SHOWONLY = YES;
}
initmainnwcalls();
printf("Scanning for server(s). . .");
servercount = scanforservers();
printf("DONE. . .%d found\nScanning for attached servers. . .",servercount);
for (loop=0;loop<=servercount;loop++)
serversattached = getserverinfo(loop);
printf("DONE. . .\nAttached to %d servers.\n",serversattached);
for (loop=0;loop<serversattached;loop++)
GetQueues(loop);
// checklpts();
if (SHOWONLY == NO)
{ clrscr();
while (!kbhit())
{ for (loop=0;loop<maincounter;loop++)
ScanQueues(loop);
}
} // if
_setcursortype(_NORMALCURSOR);
} // main
// init the 3 main nwcalls
void initmainnwcalls()
{ WORD nwrc;
nwrc = (NWCallsInit(NULL, NULL));
if (nwrc != 0x0000)
{ printf("\nNWCallsInit: failed %04x",nwrc);
getch(); exit(1);
}
nwrc = (NWGetDefaultConnectionID(&connHandle));
if (nwrc != 0x0000)
{ printf("\nNWGetDefaultConnectionID: failed %04x",nwrc);
getch(); exit(1);
}
nwrc = (NWGetConnectionNumber(connHandle, &connNumber));
if (nwrc != 0x0000)
{ printf("\nNWGetConnectionNumber: failed %04x",nwrc);
getch(); exit(1);
}
} //initmainnwcalls
// checklpts
void checklpts()
{ int loop, temp;
WORD nwrc;
printf("\nOLD SETTINGS");
for (loop=0;loop<=MAXLPTPORTS;loop++)
{ nwrc = (NWGetCaptureStatus(loop));
if (nwrc == 0x00ff)
{ nwrc = NWGetCaptureFlags(loop,(NWCAPTURE_FLAGS1 NWFAR *)&capture1,(NWCAPTURE_FLAGS2 NWFAR *)&capture2);
if (nwrc == 0x0000)
{ temp = loop;
ShowSettings(loop);
}
} // if
} // for
printf("\nNEW SETTINGS:");
capture1.flushCaptureTimeout = 6;
nwrc = NWSetCaptureFlags(connHandle,temp,(NWCAPTURE_FLAGS1 NWFAR *)&capture1);
nwrc = NWGetCaptureFlags(temp,(NWCAPTURE_FLAGS1 NWFAR *)&capture1,(NWCAPTURE_FLAGS2 NWFAR *)&capture2);
if (nwrc == 0x0000)
ShowSettings(loop);
} //checklpts
// Show the current print settings
void ShowSettings(int loop)
{ int returncode;
NWGetFileServerName(connHandle,(char NWFAR *)&servername);
printf("\nServer: %s",servername);
printf("\nCopies\tLines\tChars\tBanner Name");
printf("\n%d\t%d\t%d\t%s",capture1.numCopies,capture1.maxLines,capture1.maxChars,capture1.bannerText);
if (capture1.jobControlFlags && 0x80)
printf("\nBanner Disabled");
else
printf("\nBanner Enabled");
if (capture1.jobControlFlags & 0x08)
printf("\nForm Feed");
else
printf("\nNo Form Feed");
if (capture2.fileCaptureFlag)
printf("\nCapturing to a file");
else
if (capture2.printQueueFlag)
printf("\nLPT%d redirected to Queue = %s",loop,capture2.queueName);
if (capture1.jobControlFlags & 0x10)
printf("\nWill notify when finished.");
else
printf("\nWill not notify when finished.");
printf("\nTabs converted to %d spaces",capture1.tabSize);
if (capture1.flushCaptureTimeout == 0)
printf("\nTimeout Disabled");
else
printf("\nTimeout: %d seconds",capture1.flushCaptureTimeout);
printf("\nForm Type: %d",capture1.formType);
if (capture1.flushCaptureOnClose)
printf("\nAuto Endcap: Off");
else
printf("\nAuto Endcap: On");
} // ShowSettings
// Get a list of available Print Queues
void GetQueues(int servernum)
{
char searchObjectName[48], objectName[48], buff[48], searchPropertyName[16], propertyName[16];
char propertyFlags, propertySecurity,propertyHasValue, moreProperties;
NWOBJ_TYPE searchObjectType, objectType, tmpType;
NWFLAGS hasPropertiesFlag, objectFlag, objectSecurity, objectHasProperties;
BYTE propertyValue[128], moreSegments, accessLevel;
NWOBJ_ID objectID = -1;
WORD connType, spxID;
DWORD connID;
int counter=0,loop, counter2=0;
char printservername[16][48];
NWNUM queueStartPosition;
QueueJobListReply job;
// strcpy(searchObjectName,"*");
// searchObjectType = OT_PRINT_SERVER;
// while (! (NWScanObject(raj[servernum].yourconnHandle,searchObjectName,OT_PRINT_SERVER,
// &objectID,objectName,&objectType,&objectHasProperties,
// &objectFlag,&objectSecurity)))
// strcpy(raj[servernum].printserver[counter2++],objectName);
// raj[servernum].numberofprintservers = counter2 - 1;
// next five lines can be // out
// printf("\n\nSERVER: %s",raj[servernum].servername);
// printf("\nPrint Servers:");
// for (loop=0;loop<counter2;loop++)
// printf("\n%s",raj[servernum].printserver[loop]);
printf("\n\nPrint Queues:");
strcpy(searchObjectName,"*");
searchObjectType = OT_PRINT_QUEUE;
while (! (NWScanObject(raj[servernum].yourconnHandle,searchObjectName,OT_PRINT_QUEUE,
&objectID,objectName,&objectType,&objectHasProperties,
&objectFlag,&objectSecurity)))
{ strcpy(raj[servernum].queuename[counter],objectName);
raj[servernum].queueid[counter++] = objectID;
if (SHOWONLY == YES)
printf("\n%d.\t%s",counter-1,objectName);
}
raj[servernum].numberofqueues = counter - 1;
} // GetQueues
// scan the queue for print jobs
void ScanQueues(int snum)
{ char username[48];
NWNUM queueStartPosition=1;
QueueJobListReply job;
NWQueueJobStruct job2;
int loop,loop2,loop3,temp;
static int prevjobnumber;
NWSIZE fileSize;
WORD nwrc;
FILE *tempfile;
NWOBJ_TYPE objectType;
clrscr();
for (loop=0;loop<=raj[snum].numberofqueues;loop++)
{ gotoxy(1,1);
printf("\nScanning print queues on server %s for a print job. . .", raj[snum].servername);
// delay(500);
for(loop2=0;loop2<=raj[snum].numberofqueues;loop2++)
{ NWGetQueueJobList2(raj[snum].yourconnHandle,raj[snum].queueid[loop2],queueStartPosition,(QueueJobListReply NWFAR *)&job);
if (job.totalQueueJobs != 0)
{ printf("\nServer: %s\tQueue: %s\t# of Jobs: %d",raj[snum].servername,raj[snum].queuename[loop2],job.totalQueueJobs);
printf("\nPos #\tFile Size\tUser Name");
for (loop3=0;loop3<job.totalQueueJobs;loop3++)
if (prevjobnumber != job.jobNumberList[loop3])
{ printf("\n%d",loop3);
nwrc = NWGetQueueJobFileSize2(raj[snum].yourconnHandle,raj[snum].queueid[loop2],job.jobNumberList[loop3],(NWSIZE NWFAR *)&fileSize);
if (nwrc == 0x0000)
printf("\t%ld",fileSize);
else
printf("\nFileSize failed: %04x",nwrc);
nwrc = NWReadQueueJobEntry2(raj[snum].yourconnHandle,raj[snum].queueid[loop2],job.jobNumberList[loop3],(NWQueueJobStruct NWFAR *)&job2);
if (nwrc == 0x0000)
{ NWGetObjectName(raj[snum].yourconnHandle,job2.clientID,(char NWFAR *)&username,(NWOBJ_TYPE NWFAR *)&objectType);
printf("\t\t%s",username);
}
else
printf("\nJobEntry failed: %04x",nwrc);
prevjobnumber = job.jobNumberList[loop3];
delay(500);
} // if
} // if
} // for
} // for
} // ScanQueues
// scan the bindery for servers
int scanforservers()
{ int binerror = 0, counter=0;
WORD nwrc;
char searchName[48], objectName[48];
NWOBJ_TYPE searchType = OT_FILE_SERVER, objectType;
NWOBJ_ID objectID = -1;
NWFLAGS hasPropertiesFlag, objectFlags, objectSecurity;
strcpy(searchName,"*");
while (binerror == 0)
{
nwrc = (NWScanObject(connHandle, (char NWFAR *)searchName, searchType, (NWOBJ_ID NWFAR *)&objectID,
(char NWFAR *)&objectName, (NWOBJ_TYPE NWFAR *)&objectType, (NWFLAGS NWFAR *)&hasPropertiesFlag,
(NWFLAGS NWFAR *)&objectFlags, (NWFLAGS NWFAR *)&objectSecurity));
if (nwrc != 0x0000)
{ //printf("\nNWScanObject failed: %x",nwrc);
binerror = 1; //getch(); exit(1);
}
else
{ binerror = 0;
strcpy(serverlist[counter].name,objectName);
counter++;
}
} // while
return(counter);
} //scanforservers
// get information on a server
int getserverinfo(servernum)
{ int error = 0; WORD nwrc;
VERSION_INFO fsinfotemp;
static unsigned int servercount;
NWCONN_HANDLE tempconnHandle;
int tempconnNumber;
nwrc = (NWGetConnectionHandle((BYTE NWFAR *)&serverlist[servernum].name, 0,(NWCONN_HANDLE NWFAR *)&tempconnHandle, NULL));
if (nwrc != 0x0000)
{ // printf("\nNWGetConnectionHandle failed: %x",nwrc);
// getch(); exit(1);
error = 1;
}
if (error == 0)
{ nwrc = (NWGetConnectionNumber(tempconnHandle, &tempconnNumber));
if (nwrc != 0x0000)
{ printf("\nNWGetConnectionNumber failed: %x",nwrc);
exit(1);
}
nwrc = (NWGetFileServerVersionInfo(tempconnHandle, (VERSION_INFO FAR *)&fsinfotemp));
if (nwrc != 0x0000)
{ printf("\nNWGetFileServerVersionInfo: failed %04x",nwrc);
exit(1);
}
strcpy(raj[maincounter].servername,fsinfotemp.serverName);
raj[maincounter].yourconnNumber = tempconnNumber;
raj[maincounter++].yourconnHandle = tempconnHandle;
strcpy(serverinfo[servercount].name,fsinfotemp.serverName);
serverinfo[servercount].connsinuse = fsinfotemp.connectionsInUse;
serverinfo[servercount].yourconnNumber = tempconnNumber;
serverinfo[servercount].yourconnHandle = tempconnHandle;
servercount++;
} //if error
return(servercount);
} //getserverinfo
// Get connection info based on the connection number and connection handle
void getconninfo(NWCONN_HANDLE chandle,NWCONN_NUM cnum)
{ WORD nwrc;
nwrc = NWGetConnectionInformation(chandle,cnum,(char NWFAR *)userinfo.objname,(WORD FAR *)&userinfo.objtype,(DWORD FAR *)&userinfo.objID,(BYTE FAR *)userinfo.logintime);
if (nwrc != 0x0000)
{ clrscr();
printf("NWGetConnectionInformation failed: %x",nwrc);
getch();
}
} //getconninfo
void displayhelp()
{
clrscr();
printf("\nFILE: PRINTQ.EXE");
printf("\n\nSyntax: printq [/? | /q]");
printf("\nThe /? option display this screen.");
printf("\nThe /q option will display all print queues that exist on the servers");
printf("\nyou are attached to.");
printf("\nNo option will show any print jobs that are currently in the queue.");
printf("\nIt will also display the owner of the job, job number, and size of the job.");
printf("\n\nNOTE: When no options are used, the program runs until you hit a key.");
} // displayhelp
// Close all open Windows
void CloseAllWindows()
{ int loop;
for(loop=wnum;loop==0;loop--)
CloseTopWindow(&buffer[loop]);
wnum=0;
}